package com.ctgu.蓝桥杯真题.B组2017;

import java.io.*;
import java.util.Arrays;

/**
 * @author: Backdiy
 * @data: 2021/4/14 14:08
 * @desc:
 */
public class B纸牌三角形 {
    static int ans =0;
    public static void main(String[] args) {
        int[] num = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
        p(num, 0, 8);
        //去重分别为顺时针和逆时针，每一种有3种重复，所以除6
        IO.out.println(ans/6);
        IO.out.flush();
    }
    //找到第一个大于target的元素下标
    int upperBound(int[] a,int l,int r,int target){
        while (l<r){
            int mid = (r-l)/2+l;
            if(target>=a[mid]) l=mid+1;
            else r=mid;
        }
        return l;
    }
    //找到第一个大于等于target的元素下标
    int lowerBound(int[] a,int l,int r,int target){
        while (l<r){
            int mid = (r-l)/2+l;
            if(target>a[mid]) l=mid+1;
            else r=mid;
        }
        return l;
    }
    static void p(int[] num, int st, int ed) {
        if (st == ed) {
            int a = num[0]+num[1]+num[2]+num[3];
            int b = num[3]+num[4]+num[5]+num[6];
            int c = num[6]+num[7]+num[8]+num[0];
            if(a==b && a==c){
                ans++;
            }
        } else {
            for (int i = st; i <= ed; i++) {
                swap(num, st, i);
                p(num, st + 1, ed);
                swap(num, st, i);
            }
        }
    }

    static void swap(int[] num, int st, int ed) {
        int t = num[st];
        num[st] = num[ed];
        num[ed] = t;
    }

    static class IO {
        static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        static public int nextInt() throws IOException {
            in.nextToken();
            return (int) in.nval;
        }

        static public String readLine() throws IOException {
            return read.readLine();
        }
    }
}
